Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby-source-graphql): Default Apollo Link fetch wrapper to show better API errors #28786

Merged
merged 3 commits into from
Dec 29, 2020
Merged

feat(gatsby-source-graphql): Default Apollo Link fetch wrapper to show better API errors #28786

merged 3 commits into from
Dec 29, 2020

Conversation

antoinerousseau
Copy link
Contributor

@antoinerousseau antoinerousseau commented Dec 29, 2020

Description

When the source GraphQL API responds with an error (4xx/5xx), the default behavior is to try to read the response body anyway, which is, in case of errors, often unrelated JSON, or HTML, or empty.
In these cases, we throw an error showing the HTTP response code and status text, which is much more relevant.
The user is still free to override the default fetch wrapper anyway.

Documentation

https://www.gatsbyjs.com/plugins/gatsby-source-graphql/#how-to-use
https://www.apollographql.com/docs/link/links/http/#fetch-polyfill

Related Issues

#10487
#20892
#28766

Notes

We could add more logging by passing the reporter to the wrapper and add some reporter.verbose(...) for stuff like the response body or the request body, but it might be better to leave that to the user since they can write their own fetch wrapper anyway.

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Dec 29, 2020
@antoinerousseau antoinerousseau changed the title [gatsby-source-graphql] Default Apollo Link fetch wrapper to show better API errors feat(gatsby-source-graphql): Default Apollo Link fetch wrapper to show better API errors Dec 29, 2020
@KyleAMathews
Copy link
Contributor

@vladar vladar added topic: GraphQL Related to Gatsby's GraphQL layer and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Dec 29, 2020
@vladar
Copy link
Contributor

vladar commented Dec 29, 2020

I've updated those failing tests

Copy link
Contributor

@vladar vladar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement, thanks!

Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@vladar vladar added the bot: merge on green Gatsbot will merge these PRs automatically when all tests passes label Dec 29, 2020
@vladar vladar merged commit abdb8d6 into gatsbyjs:master Dec 29, 2020
@antoinerousseau
Copy link
Contributor Author

Wow great, that was fast, thanks!

@antoinerousseau antoinerousseau deleted the source-graphql branch December 30, 2020 18:01
pragmaticpat pushed a commit to pragmaticpat/gatsby that referenced this pull request Apr 28, 2022
…w better API errors (gatsbyjs#28786)

* apollo fetch http error status

* update tests

Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: merge on green Gatsbot will merge these PRs automatically when all tests passes topic: GraphQL Related to Gatsby's GraphQL layer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants